#include<bits/stdc++.h>
using namespace std;

//求最长连续字符的次数
void fun(string s){
    char maxch=s[0];
    int maxCount=0;
    for(int i=0;i<s.size();i++){
        int count=1,j;
        for(j=i+1;j<s.size()&&s[j]==s[i];j++){
            count++;
        }
        if(count>maxCount){
            maxCount=count;
            maxch=s[i];
        }
        i=j;
    }
    cout<<maxch<<" "<<maxCount<<endl;
}

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        fun(str);
    }
    return 0;
}
